home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Texteditors / Origami / bindings / fun / file-buffers < prev    next >
Encoding:
Text File  |  1996-09-27  |  4.1 KB  |  141 lines

  1. ;OCL{{{}}}
  2. ;OCL{{{  comments
  3. ; this macro package can read/savte the kill-/delete- and move-buffer from/to
  4. ; files. Therefor it must enter a filed fold, so that the currently edited
  5. ; file will be saved.
  6. ; If no tag DUMP-FILE is set, the file `~/.origamibuf' is used. Otherwise
  7. ; you have to define a macro 'dump-file', which generates the filename on a
  8. ; empty text-line.
  9. ;OCL}}}
  10. @if-using not(ocl-file-file-buffers)
  11.    @use (ocl-file-file-buffers)
  12.    ;OCL{{{  libs
  13.    @if-using not(ocl-file-error)       @lib error       @fi
  14.    @if-using not(ocl-file-hide-buffer) @lib hide-buffer @fi
  15.    ;OCL}}}
  16.    ;OCL{{{  bf-action
  17.    @if-using not(DUMP-FILE)
  18.       ;OCL{{{  dump-file
  19.       ( defmac dump-file ( "~ insert-ascii path-separator ".origamibuf ) )
  20.       ;OCL}}}
  21.    @fi
  22.    ( defvar ( bf-save bf-error bf-buff-id bf-dummy-buff-id ) )
  23.  
  24.    ( deffun bf-action
  25.       ( if in-prompt ( return-from-macro ) fi
  26.         set bf-buff-id current-buffer-id
  27.         open-hidden-dummy-buffer(false)
  28.         set bf-dummy-buff-id current-buffer-id
  29.         ;OCL{{{  save the buffers to dummy-buffer
  30.         ;OCL{{{  set language
  31.         if not(test-language Inmos) ( set-language Inmos ) fi
  32.         ;OCL}}}
  33.         ;OCL{{{  move
  34.         beginning-of-line create-fold create-fold "move
  35.         enter-fold move-line exit-fold
  36.         ;OCL}}}
  37.         ;OCL{{{  delete
  38.         beginning-of-line create-fold create-fold "delete
  39.         enter-fold
  40.         ;OCL{{{  undelete all lines
  41.         if last-message M_NO_UNDEL () fi
  42.         do
  43.          ( undo-delete-line )
  44.         while not(last-message M_NO_UNDEL)
  45.         ;OCL}}}
  46.         exit-fold
  47.         ;OCL}}}
  48.         ;OCL{{{  kill
  49.         beginning-of-line create-fold create-fold "kill
  50.         enter-fold insert-folded-kill-buffer unfold-fold exit-fold
  51.         ;OCL}}}
  52.         ;OCL}}}
  53.         if last-message M_CANTOPEN () fi
  54.         if last-message M_CANTWRITE () fi
  55.         if bf-save
  56.          ;OCL{{{  save file
  57.          ( write-file dump-file newline-and-indent )
  58.          ;OCL}}}
  59.         else
  60.          ;OCL{{{  try to insert the saved buffers to the beginning of the file!
  61.          ( beginning-of-fold
  62.            next-line
  63.            insert-file dump-file newline-and-indent
  64.          )
  65.          ;OCL}}}
  66.         fi
  67.         set bf-error
  68.             counter or (last-message M_CANTOPEN last-message M_CANTWRITE)
  69.         ;OCL{{{  read the buffers
  70.         local
  71.          ()
  72.          ( beginning-of-fold
  73.            next-line
  74.            if test-fold-line
  75.             ( enter-fold
  76.               while not( test-end-fold ) ( kill-line )
  77.               exit-fold
  78.               next-line
  79.               if test-fold-line
  80.                ( enter-fold
  81.                  while not(test-bottom) ( delete-line )
  82.                  exit-fold
  83.                  next-line
  84.                  if test-fold-line
  85.                   ( enter-fold
  86.                     move-line
  87.                     exit-fold
  88.                     return-from-macro
  89.                   )
  90.                  fi
  91.                )
  92.               fi
  93.             )
  94.            fi
  95.            set bf-error true
  96.          )
  97.         ;OCL}}}
  98.         leave-hidden-dummy-buffer(bf-buff-id)
  99.         set bf-dummy-buff-id current-buffer-id
  100.         redraw-display
  101.         if bf-error ( message ( M_FAILED ) ) fi
  102.       )
  103.    )
  104.    ;OCL}}}
  105.    ;OCL{{{  dump-buffers-to-file
  106.    ( deffun dump-buffers-to-file ( set bf-save 1 bf-action ) )
  107.    ;OCL}}}
  108.    ;OCL{{{  get-buffers-from-file
  109.    ( deffun get-buffers-from-file ( set bf-save 0 bf-action ) )
  110.    ;OCL}}}
  111.    ;OCL{{{  abort-hook-add
  112.    @if-using not(ABORT-HOOK-ADD)
  113.       @use (ABORT-HOOK-ADD)
  114.       ( defmac abort-hook-add ( ) )
  115.    @fi
  116.    ( defmac abort-hook-add-saved ( abort-hook-add ) )
  117.    ( undeclare ( abort-hook-add ) )
  118.    ( defmac abort-hook-add
  119.       ( abort-hook-add-saved
  120.         if bf-dummy-buff-id
  121.          ( goto-buffer-id bf-dummy-buff-id
  122.            set-file-unchanged
  123.            set bf-dummy-buff-id 0
  124.          )
  125.         fi
  126.       )
  127.    )
  128.    ( undeclare ( abort-hook-add-saved ) )
  129.    ;OCL}}}
  130.    ;OCL{{{  undeclares
  131.    ( undeclare
  132.       ( bf-action
  133.         bf-save
  134.         bf-error
  135.         bf-dummy-buff-id
  136.         @if-using not( DUMP-FILE ) dump-file @fi
  137.       )
  138.    )
  139.    ;OCL}}}
  140. @fi
  141.